<?php
/**
 * Created by PhpStorm.
 * User: Sixstar-Peter
 * Date: 2019/4/19
 * Time: 20:53
 */

use Swoole\Coroutine;

class Context
{

    static function get($key)
    {
        $cid = Coroutine::getuid();
        if ($cid < 0) {
            return null;
        }
        if (isset(self::$pool[$cid][$key])) {
            return self::$pool[$cid][$key];
        }
        return null;
    }

    static function put($key, $item)
    {
        //假设一个协程当中设置了两次数据

        $context = Co::getContext();
        $context[$key] = $item;
    }

    public static function setContextData(array $contextData = [])
    {
        $existContext = [];
        $context = Co::getContext();
        if (isset($context['data'])) {
            $existContext = $context['data'];
        }
        $context[['data']] = array_merge($contextData, $existContext);
    }


}